package com.gzhryc.pay.adaptation.alipay.msg.native_pay;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.gzhryc.common.NumberTools;
import com.gzhryc.common.json.JsonTools;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Map;

public class AlipayNativePayNotify implements Serializable {

    private static final long serialVersionUID = 1L;

    final Map<String, String> params;
    final String payKey;

    public AlipayNativePayNotify(Map<String, String> params, String payKey) {
        this.params = params;
        this.payKey = payKey;
    }

    public String getTradeNo() {
        return this.params != null ? this.params.get("out_trade_no") : null;
    }

    public String getExternalTradeNo() {
        return this.params != null ? this.params.get("trade_no") : null;
    }

    public Integer getMoney() {
        if (this.params != null) {
            String totalAmount = this.params.get("total_amount");
            if (StringUtils.isNotBlank(totalAmount)) {
                try {
                    return NumberTools.changeMoney(Double.valueOf(totalAmount));
                } catch (Exception var3) {
                    var3.printStackTrace();
                }
            }
        }

        return null;
    }

    public String getTradeStatus() {
        if (params != null) {
            return params.get("trade_status");
        }
        return null;
    }

    public boolean isTrue() {
        if (StringUtils.isNotBlank(this.payKey)) {
            try {
                return AlipaySignature.rsaCheckV1(this.params, this.payKey, "UTF-8", "RSA2");
            } catch (AlipayApiException var2) {
                var2.printStackTrace();
            }
        }

        return false;
    }

    public Map<String, String> getParams() {
        return params;
    }

    public String getJson() {
        return this.params != null ? JsonTools.toJson(this.params) : null;
    }
}

